#include <stdlib.h>

#include "packet_factory.h"

/*
 * Generic packet factory
 */
PACKET_HDR* create_packet( PACKET_TYPE type )
{
	PACKET_HDR* packet = (PACKET_HDR*) malloc( sizeof(PACKET_HDR) );
	
	packet->id_packet = type;
	
	return packet;
}

/*
 * Specific packet factories
 */
COMMAND_OK_PACKET* create_packet_command_ok( int16_t id_command )
{
	COMMAND_OK_PACKET* packet = (COMMAND_OK_PACKET*) malloc( sizeof(COMMAND_OK_PACKET) );
	
	packet->hdr.id_packet 	= PACKET_COMMAND_OK;
	packet->id_command 		= id_command;
	
	return packet;
}

STATUS_PACKET* create_packet_status( int16_t num_lot, int16_t time, int16_t num_box, int16_t nb_defect_piece )
{
	STATUS_PACKET* packet = (STATUS_PACKET*) malloc( sizeof(STATUS_PACKET) );
	
	packet->hdr.id_packet 	= PACKET_STATUS;
	packet->num_lot			= num_lot;
	packet->time			= time;
	packet->num_box			= num_box;
	packet->nb_defect_piece = nb_defect_piece;
	
	return packet;
}

ERROR_PACKET* create_packet_error( int8_t id_error, int16_t parameter )
{
	ERROR_PACKET* packet = (ERROR_PACKET*) malloc( sizeof(ERROR_PACKET) );
	
	packet->hdr.id_packet 	= PACKET_ERROR;
	packet->parameter		= parameter;		
		
	return packet;	
}
